package com.zadtek.sharkRider.activity.adapter;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zadtek.sharkRider.R;
import com.zadtek.sharkRider.activity.SygOrdDetailActivity_;
import com.zadtek.sharkRider.activity.common.Common;
import com.zadtek.sharkRider.activity.data.OrderNewHelpData;
import com.zadtek.sharkRider.views.OnChanged;

/**
 * 待取货
 * 
 * @author kywwl
 * 
 */
public class OrderWaitHelpAdapter extends CommonAdapter<OrderNewHelpData> {
	private OnChanged listener;

	public OrderWaitHelpAdapter(Context context, List<OrderNewHelpData> datas,
			int layoutId) {
		super(context, datas, layoutId);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void convert(ViewHolders holder, final OrderNewHelpData t) {
		ImageView newtask_order_img = holder.getView(R.id.newtask_order_img);
		TextView newtaskmomey = holder.getView(R.id.newtask_money);
		TextView newtasktime = holder.getView(R.id.newtask_time);

		TextView newtask_goods_name = holder.getView(R.id.newtask_goods_name);
		TextView newtask_goods_address = holder
				.getView(R.id.newtask_goods_address);
		TextView help_goods_distance = holder.getView(R.id.help_goods_distance);
		TextView newtask_goods_distance = holder
				.getView(R.id.newtask_goods_distance);
		LinearLayout wait_layout =holder.getView(R.id.wait_layout);
		newtask_goods_name.setText(t.getTitle());
		newtask_goods_address.setText(t.getGet_address());
		LinearLayout newhelp_layout = holder.getView(R.id.newhelp_layout);
		if (t.getGet_address().length() > 0) {
			newtask_goods_address.setVisibility(View.VISIBLE);
		} else {
			newtask_goods_address.setVisibility(View.GONE);
		}
		
		if (t.getType().equals("buy")) {
			newtask_order_img.setImageResource(R.drawable.gou);
		} else if (t.getType().equals("get")) {
			newtask_order_img.setImageResource(R.drawable.qu);
		} else if (t.getType().equals("send")) {
			newtask_order_img.setImageResource(R.drawable.fa);
		}
		
		LinearLayout juli_layout01 =holder.getView(R.id.juli_layout01);
		if (!t.getLocation_get().equals("0")) {
			help_goods_distance.setText(t.getLocation_get() + "Km");
			juli_layout01.setVisibility(View.VISIBLE);
		} else {
			juli_layout01.setVisibility(View.GONE);
		}
		if (!t.getLocation_send().equals("0")) {
			newtask_goods_distance.setText(t.getLocation_send() + "Km");
			wait_layout.setVisibility(View.VISIBLE);
		} else {
			wait_layout.setVisibility(View.GONE);
		}

		TextView newtask_goods_getaddress = holder
				.getView(R.id.newtask_goods_getaddress);
		TextView getgpsaddr = holder.getView(R.id.getgpsaddr);
		newtaskmomey.setText("￥" + t.getPercentage());
		if (!t.getHelp_addtime().equals("") || t.getHelp_addtime() != null) {
			newtasktime.setText(Common.getStrTime(t.getHelp_addtime()));
		}
		newtask_goods_getaddress.setText(t.getSend_address());

		LinearLayout submitthread = holder.getView(R.id.help_submit);
		submitthread.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				if (t.getHelp_order_id() != null
						&& !t.getHelp_order_id().equals("")) {
					Intent intent = new Intent(mContext,
							SygOrdDetailActivity_.class);
					intent.putExtra("mainid", t.getHelp_order_id());
					intent.putExtra("location", t.getLocation_send());
					intent.putExtra("location_get", t.getLocation_get());
					mContext.startActivity(intent);
				}
			}
		});

		try {
			String address_road = t.getMap_location();
			if (address_road == null || address_road.equals("")
					|| address_road.equals("null")) {
				getgpsaddr.setVisibility(View.GONE);
			} else {
				getgpsaddr.setText(address_road); // 根据经纬度反查地址
				getgpsaddr.setVisibility(View.VISIBLE);
			}
		} catch (Exception e) {
		}

	}
}
